


use "${pathdata_robustness}/RobustnessExperiment2.dta", clear

* ########## DEFINE VARIABLES ##########
	
	* Indicator whether both type and recall are remembered correctly
	gen correct_combined = 0
	replace correct_combined = 1 if correct_type == 1 & correct_valence == 1
	
	* Belief movement variable
	gen delta = effect_recall - effect
	keep delta product correct_combined bonusproduct prolific_pid condition_ treatment
	reshape wide (delta correct_combined) condition_ , i(prolific_pid) j(product) string // Make data set wide

	* Reorder treatments for the table. order is 4 2 3 7 5 6
	gen type = .
	
	replace type = 1 if treatment == 4
	replace type = 2 if treatment == 2
	replace type = 3 if treatment == 3
	replace type = 4 if treatment == 7
	replace type = 5 if treatment == 5
	replace type = 6 if treatment == 6

	
		
		*############ Target: Belief Movement Variable ############
		
		
		gen delta = .
		
		* Target: Story | Decoy: NoInfo/Stats
		* Treatments 3 and 4 only have 1 story -> We are interested in the one with the story
		replace delta = deltabicycle if inlist(condition_bicycle, "storyshort_pos", "storyshort_neg") & inlist(treatment, 3,4)
		replace delta = deltarestaurant if inlist(condition_restaurant, "storyshort_pos", "storyshort_neg") & inlist(treatment, 3,4)
		replace delta = deltavideogame if inlist(condition_videogame, "storyshort_pos", "storyshort_neg") & inlist(treatment, 3,4)
		
		* Target = Decoy type
		* Here, all 3 are stories/statistics. We randomly select 1 as target. Bonusproduct is randomly generated with a uniform distribution over {bicycle, restaurant, videogame}
		replace delta = deltabicycle if bonusproduct == "bicycle" & inlist(treatment, 2,6)
		replace delta = deltarestaurant if bonusproduct == "restaurant" & inlist(treatment, 2,6)
		replace delta = deltavideogame if bonusproduct == "videogame" & inlist(treatment, 2,6)

		
		* Target: Stats | Decoy: NoInfo/Story
		* Treatments 5 and 7 only have 1 statistic -> We are interested in the one with the statistic
		replace delta = deltabicycle if inlist(condition_bicycle, "statistic_pos", "statistic_neg") &  inlist(treatment, 5,7)
		replace delta = deltarestaurant if inlist(condition_restaurant, "statistic_pos", "statistic_neg") & inlist(treatment, 5,7)
		replace delta = deltavideogame if inlist(condition_videogame, "statistic_pos", "statistic_neg") & inlist(treatment, 5,7)
		
		
		gen correct_combined = .
		
		* Target: Story | Decoy: NoInfo/Stats
		* Treatments 3 and 4 only have 1 story -> We are interested in the one with the story
		replace correct_combined = correct_combinedbicycle if inlist(condition_bicycle, "storyshort_pos", "storyshort_neg") & inlist(treatment, 3,4)
		replace correct_combined = correct_combinedrestaurant if inlist(condition_restaurant, "storyshort_pos", "storyshort_neg") & inlist(treatment, 3,4)
		replace correct_combined = correct_combinedvideogame if inlist(condition_videogame, "storyshort_pos", "storyshort_neg") & inlist(treatment, 3,4)
		
		* Target = Decoy type
		* Here, all 3 are stories/statistics. We randomly select 1 as target. Bonusproduct is randomly generated with a uniform distribution over {bicycle, restaurant, videogame}
		replace correct_combined = correct_combinedbicycle if bonusproduct == "bicycle" & inlist(treatment, 2,6)
		replace correct_combined = correct_combinedrestaurant if bonusproduct == "restaurant" & inlist(treatment, 2,6)
		replace correct_combined = correct_combinedvideogame if bonusproduct == "videogame" & inlist(treatment, 2,6)

		
		* Target: Stats | Decoy: NoInfo/Story
		* Treatments 5 and 7 only have 1 statistic -> We are interested in the one with the statistic
		replace correct_combined = correct_combinedbicycle if inlist(condition_bicycle, "statistic_pos", "statistic_neg") &  inlist(treatment, 5,7)
		replace correct_combined = correct_combinedrestaurant if inlist(condition_restaurant, "statistic_pos", "statistic_neg") & inlist(treatment, 5,7)
		replace correct_combined = correct_combinedvideogame if inlist(condition_videogame, "statistic_pos", "statistic_neg") & inlist(treatment, 5,7)

		
		
		
	* ########## Decoy Valence ##########
	* 1: Same Valence
	* 2: Mixed Valence
	* 3: Opposite Valence
		
		* As 1 2 3 form a partition, we take 2 as basis
		gen decoy_valence =2
		
		/*
		
		Note: this is a little tedious but we just handcode all the possible
		combinations of stories and statistics + their possible valence		
		
		*/
		
		******************* Treatments 3 and 5 *******************
		
		* Target: Story | Decoy: Stat | Valence: Same
		replace decoy_valence = 1 if condition_restaurant == "statistic_pos" & condition_videogame == "statistic_pos" & condition_bicycle == "storyshort_pos"
		replace decoy_valence = 1 if condition_bicycle == "statistic_pos" & condition_restaurant == "statistic_pos" & condition_videogame == "storyshort_pos"
		replace decoy_valence = 1 if condition_videogame == "statistic_pos" & condition_bicycle == "statistic_pos" & condition_restaurant == "storyshort_pos"
		replace decoy_valence = 1 if condition_restaurant == "statistic_neg" & condition_videogame == "statistic_neg" & condition_bicycle == "storyshort_neg"
		replace decoy_valence = 1 if condition_bicycle == "statistic_neg" & condition_restaurant == "statistic_neg" & condition_videogame == "storyshort_neg"
		replace decoy_valence = 1 if condition_videogame == "statistic_neg" & condition_bicycle == "statistic_neg" & condition_restaurant == "storyshort_neg"
		
		* Target: Story | Decoy: Stat | Valence: Opposite
		replace decoy_valence = 3 if condition_restaurant == "statistic_pos" & condition_videogame == "statistic_pos" & condition_bicycle == "storyshort_neg"
		replace decoy_valence = 3 if condition_bicycle == "statistic_pos" & condition_restaurant == "statistic_pos" & condition_videogame == "storyshort_neg"
		replace decoy_valence = 3 if condition_videogame == "statistic_pos" & condition_bicycle == "statistic_pos" & condition_restaurant == "storyshort_neg"
		replace decoy_valence = 3 if condition_restaurant == "statistic_neg" & condition_videogame == "statistic_neg" & condition_bicycle == "storyshort_pos"
		replace decoy_valence = 3 if condition_bicycle == "statistic_neg" & condition_restaurant == "statistic_neg" & condition_videogame == "storyshort_pos"
		replace decoy_valence = 3 if condition_videogame == "statistic_neg" & condition_bicycle == "statistic_neg" & condition_restaurant == "storyshort_pos"

		
		* Target: Stat | Decoy: Story | Valence: Same
		replace decoy_valence = 1 if condition_restaurant == "storyshort_pos" & condition_videogame == "storyshort_pos" & condition_bicycle == "statistic_pos"
		replace decoy_valence = 1 if condition_bicycle == "storyshort_pos" & condition_restaurant == "storyshort_pos" & condition_videogame == "statistic_pos"
		replace decoy_valence = 1 if condition_videogame == "storyshort_pos" & condition_bicycle == "storyshort_pos" & condition_restaurant == "statistic_pos"
		replace decoy_valence = 1 if condition_restaurant == "storyshort_neg" & condition_videogame == "storyshort_neg" & condition_bicycle == "statistic_neg"
		replace decoy_valence = 1 if condition_bicycle == "storyshort_neg" & condition_restaurant == "storyshort_neg" & condition_videogame == "statistic_neg"
		replace decoy_valence = 1 if condition_videogame == "storyshort_neg" & condition_bicycle == "storyshort_neg" & condition_restaurant == "statistic_neg"
		
		* Target: Stat | Decoy: Story | Valence: Opposite
		replace decoy_valence = 3 if condition_restaurant == "storyshort_pos" & condition_videogame == "storyshort_pos" & condition_bicycle == "statistic_neg"
		replace decoy_valence = 3 if condition_bicycle == "storyshort_pos" & condition_restaurant == "storyshort_pos" & condition_videogame == "statistic_neg"
		replace decoy_valence = 3 if condition_videogame == "storyshort_pos" & condition_bicycle == "storyshort_pos" & condition_restaurant == "statistic_neg"
		replace decoy_valence = 3 if condition_restaurant == "storyshort_neg" & condition_videogame == "storyshort_neg" & condition_bicycle == "statistic_pos"
		replace decoy_valence = 3 if condition_bicycle == "storyshort_neg" & condition_restaurant == "storyshort_neg" & condition_videogame == "statistic_pos"
		replace decoy_valence = 3 if condition_videogame == "storyshort_neg" & condition_bicycle == "storyshort_neg" & condition_restaurant == "statistic_pos"
		
		
		
		******************* Treatments 3 and 5 *******************
		* Again, as all events are either stories or statistics, we have no clear target / decoy
		* We randomly assign one of the 3 the target role via the randomly generated "Bonusproduct"
		
		
		* Target: Story | Decoy: Story | Valence: Same
		replace decoy_valence = 1 if condition_restaurant == "storyshort_pos" & condition_videogame == "storyshort_pos" & bonusproduct == "bicycle" &  & condition_bicycle == "storyshort_pos"
		replace decoy_valence = 1 if condition_bicycle == "storyshort_pos" & condition_restaurant == "storyshort_pos" & bonusproduct == "videogame" &  & condition_videogame == "storyshort_pos"
		replace decoy_valence = 1 if condition_videogame == "storyshort_pos" & condition_bicycle == "storyshort_pos" & bonusproduct == "restaurant" &  & condition_restaurant == "storyshort_pos"
		replace decoy_valence = 1 if condition_restaurant == "storyshort_neg" & condition_videogame == "storyshort_neg" & bonusproduct == "bicycle" &  condition_bicycle == "storyshort_neg"
		replace decoy_valence = 1 if condition_bicycle == "storyshort_neg" & condition_restaurant == "storyshort_neg" & bonusproduct == "videogame" & condition_videogame == "storyshort_neg"
		replace decoy_valence = 1 if condition_videogame == "storyshort_neg" & condition_bicycle == "storyshort_neg" & bonusproduct == "restaurant" & condition_restaurant == "storyshort_neg"
		
		
		* Target: Story | Decoy: Story | Valence: Opposite
		replace decoy_valence = 3 if condition_restaurant == "storyshort_neg" & condition_videogame == "storyshort_neg" & bonusproduct == "bicycle" &  condition_bicycle == "storyshort_pos"
		replace decoy_valence = 3 if condition_bicycle == "storyshort_neg" & condition_restaurant == "storyshort_neg" & bonusproduct == "videogame"  &  condition_videogame == "storyshort_pos"
		replace decoy_valence = 3 if condition_videogame == "storyshort_neg" & condition_bicycle == "storyshort_neg" & bonusproduct == "restaurant"  &  condition_restaurant == "storyshort_pos"
		replace decoy_valence = 3 if condition_restaurant == "storyshort_pos" & condition_videogame == "storyshort_pos" & bonusproduct == "bicycle"  &  condition_bicycle == "storyshort_neg"
		replace decoy_valence = 3 if condition_bicycle == "storyshort_pos" & condition_restaurant == "storyshort_pos" & bonusproduct == "videogame"  &  condition_videogame == "storyshort_neg"
		replace decoy_valence = 3 if condition_videogame == "storyshort_pos" & condition_bicycle == "storyshort_pos" & bonusproduct == "restaurant"  &  condition_restaurant == "storyshort_neg"
		
		
		
		* Target: Stat | Decoy: Stat | Valence: Same
		replace decoy_valence = 1 if condition_restaurant == "statistic_pos" & condition_videogame == "statistic_pos" & bonusproduct == "bicycle" & condition_bicycle == "statistic_pos"
		replace decoy_valence = 1 if condition_bicycle == "statistic_pos" & condition_restaurant == "statistic_pos" & bonusproduct == "videogame" & condition_videogame == "statistic_pos"
		replace decoy_valence = 1 if condition_videogame == "statistic_pos" & condition_bicycle == "statistic_pos" & bonusproduct == "restaurant" & condition_restaurant == "statistic_pos"
		replace decoy_valence = 1 if condition_restaurant == "statistic_neg" & condition_videogame == "statistic_neg" & bonusproduct == "bicycle" & condition_bicycle == "statistic_neg"
		replace decoy_valence = 1 if condition_bicycle == "statistic_neg" & condition_restaurant == "statistic_neg" & bonusproduct == "videogame" & condition_videogame == "statistic_neg"
		replace decoy_valence = 1 if condition_videogame == "statistic_neg" & condition_bicycle == "statistic_neg" & bonusproduct == "restaurant" & condition_restaurant == "statistic_neg"
		
		
		
		* Target: Stat | Decoy: Stat | Valence: Same
		replace decoy_valence = 3 if condition_restaurant == "statistic_pos" & condition_videogame == "statistic_pos" & condition_bicycle == "statistic_neg" & bonusproduct == "bicycle"
		replace decoy_valence = 3 if condition_bicycle == "statistic_pos" & condition_restaurant == "statistic_pos" & condition_videogame == "statistic_neg" & bonusproduct == "videogame"
		replace decoy_valence = 3 if condition_videogame == "statistic_pos" & condition_bicycle == "statistic_pos" & condition_restaurant == "statistic_neg" & bonusproduct == "restaurant"
		replace decoy_valence = 3 if condition_restaurant == "statistic_neg" & condition_videogame == "statistic_neg" & condition_bicycle == "statistic_pos" & bonusproduct == "bicycle"
		replace decoy_valence = 3 if condition_bicycle == "statistic_neg" & condition_restaurant == "statistic_neg" & condition_videogame == "statistic_pos" & bonusproduct == "videogame"
		replace decoy_valence = 3 if condition_videogame == "statistic_neg" & condition_bicycle == "statistic_neg" & condition_restaurant == "statistic_pos" & bonusproduct == "restaurant"
		
		
		
		
		* ########## FIGURE: THE STAT-STORY GAP BY DECOY VALENCE ##########



	* ########## BELIEF MOVEMENT ##########
	
preserve 
		
		*** WE DROP TREATMENT 4 AND 7 BECAUSE THEY INCLUDE NO ADDITIONAL INFORMATION (NoInfo)
		drop if inlist(treatment,4,7)
		
		
		collapse (mean) delta (sem) delta_sem = delta , by(decoy_valence)	 
		rename delta_sem sem0
		rename delta dev0
		gen upper=dev+sem
		gen lower=dev-sem
	
		tw (scatter dev decoy_valence if decoy_valence==1, connect(l)  mcolor(emidblue*1.5)) ///
		(scatter dev decoy_valence if decoy_valence==2, connect(l)  mcolor(emidblue*1)) ///
		(scatter dev decoy_valence if decoy_valence==3, connect(l)  mcolor(emidblue*0.6)) ///
			(rcap upper lower decoy_valence if decoy_valence==1, lw(medthick) lcolor(emidblue*1.5))  ///
			(rcap upper lower decoy_valence if decoy_valence==2, lw(medthick) lcolor(emidblue*1)) ///
			(rcap upper lower decoy_valence if decoy_valence==3, lw(medthick) lcolor(emidblue*0.6)),  ///
		ytitle("Change in belief impact {c 177} SEM" "(percentage points)") ///
			xtitle(" ", margin(t=5)) xsc(r(0.5 3.5) lcolor(none)) ysc(r(-18 0) lcolor(none)) ///
			yline(0, lcolor(gs10) lwidth(thin)) ///
			graphregion(color(white)) title("", color(emidblue)) ///
			ylabel(-18(2)0, tlc(none) angle(0) glcolor(gs15) glwidth(thin)) ///
			legend(off) ///
			xlabel(1 "Same" 2 `" "Mixed" " " "{bf: Valence}" "' 3 "Opposite")  ///
			title("Change in belief impact by decoy valence",  margin(b=3) color(black)) ysize(6) xsize(9)		
			graph export "${pathout_robustness}/figures/figureA4a.pdf", replace
			
			
restore

	* ########## CORRECT RECALL ##########

preserve 

		*** WE DROP TREATMENT 4 AND 7 BECAUSE THEY INCLUDE NO ADDITIONAL INFORMATION (NoInfo)
		drop if inlist(treatment,4,7)		
		
		* We use the correct_combined we defined above
		collapse (mean) correct_combined (sem) correct_combined_sem = correct_combined , by(decoy_valence)	 
		rename correct_combined_sem sem0
		rename correct_combined dev0
		reshape long sem dev, i(decoy_valence) j(delay)
		gen upper=dev+sem
		gen lower=dev-sem
	
		tw (scatter dev decoy_valence if decoy_valence==1, connect(l)  mcolor(emidblue*1.5)) ///
		(scatter dev decoy_valence if decoy_valence==2, connect(l)  mcolor(emidblue*1)) ///
		(scatter dev decoy_valence if decoy_valence==3, connect(l)  mcolor(emidblue*0.6)) ///
			(rcap upper lower decoy_valence if decoy_valence==1, lw(medthick) lcolor(emidblue*1.5))  ///
			(rcap upper lower decoy_valence if decoy_valence==2, lw(medthick) lcolor(emidblue*1)) ///
			(rcap upper lower decoy_valence if decoy_valence==3, lw(medthick) lcolor(emidblue*0.6)),  ///		
		ytitle("Mean Rate  {c 177} SEM") ///
			xtitle(" ", margin(t=5)) xsc(r(0.5 3.5) lcolor(none)) ysc(r(0 1) lcolor(none)) ///
			yline(0, lcolor(gs10) lwidth(thin)) ///
			graphregion(color(white)) title("", color(emidblue)) ///
			ylabel(0(0.2)1, tlc(none) angle(0) glcolor(gs15) glwidth(thin)) ///
			legend(off) ///
			xlabel(1 "Same" 2 `" "Mixed" " " "{bf: Valence}" "' 3 "Opposite") ///
			title("Correct recall of information type and valence",  color(black)) ysize(6) xsize(9)
			graph export "${pathout_robustness}/figures/figureA4b.pdf", replace
			
			
restore
		







